package com.gitee.kamismile.stone.rpc.core.handler.impl.provider.producer;

import com.gitee.kamismile.stone.rpc.api.IProtocol;
import com.gitee.kamismile.stone.rpc.api.invocation.support.StoneInvocation;
import com.gitee.kamismile.stone.rpc.common.invocation.StoneInvocationType;
import com.gitee.kamismile.stone.rpc.api.invocation.IStoneFilter;
import com.gitee.kamismile.stone.rpc.common.invocation.IStoneAsyncResponse;
import com.gitee.kamismile.stone.rpc.common.dto.StoneAppResponse;
import  org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RpcProducerFilter implements IStoneFilter {

    protected final Logger logger = LoggerFactory.getLogger(RpcProducerFilter.class);


    @Autowired
    private IProtocol iProtocol;

    @Override
    public StoneInvocationType getInvocationType() {
        return StoneInvocationType.PRODUCER;
    }

    @Override
    public int order() {
        return 100;
    }

    @Override
    public void handle(StoneInvocation stoneInvocation, IStoneAsyncResponse asyncResp) throws Exception {
        StoneAppResponse stoneAppResponse = iProtocol.refer(stoneInvocation.getType(), stoneInvocation.getStoneURL());
        asyncResp.handle(stoneAppResponse);
    }
}
